<template>
	<view class="submitorder" v-if="show_page && (shenheStatus != 1 || !shenheAliStatus)">
		<!--  #ifdef  H5 -->
		<view v-if="isofficial() && tamplate_id">
			<WxOpenSubscribe :template="tamplate_id"></WxOpenSubscribe>
		</view>
		<!--  #endif  -->
		<view :class="{ active: type_diy == 2 }" class="submitorderHdBg" :style="{ background: type_color_diy }">
			<view class="casd" :style="{ background: type_color_diy }"> </view>
		</view>

		<view class="submitOrderCon">
			<template v-if="![3].includes(mch_list[0].goods_list[0].product_type)">
			<!-- 可选DIY -->
			<view v-if="type_diy == 1">
				<distribution v-if="
            mch_list[0].goods_list[0].product_type == 0 ||
            mch_list[0].goods_list[0].product_type == 4 ||
            mch_list[0].goods_list[0].product_type == 6
          " :address="address" :send_type_arr="send_type_arr" :isShop="isShop" ref="distribution"
					@toAddress="toAddress">
				</distribution>
			</view>

			<view class="logisticsMethods" v-if="type_diy == 2" >
				<!-- 头部样式 -->
				<view class="logisticsMethods_text">
					<view v-if="type_name2 && type_name2.name" :class="{
              text_style: true,
              text_style_active2: activeIndex === 'delivery',
              text_style_active5: activeIndex === 'express',
              text_style_active8: activeIndex === 'shop'
            }" @click="handleClick(type_name2.key)">
						{{ type_name2.name }}
					</view>
					<view v-if="type_name3 && type_name3.name" :class="{
              text_style: true,
              text_style_active3: activeIndex === 'delivery',
              text_style_active6: activeIndex === 'express',
              text_style_active9: activeIndex === 'shop'
            }" @click="handleClick(type_name3.key)">
						{{ type_name3.name }}
					</view>
					<view v-if="type_name1 && type_name1.name" :class="{
              text_style: true,
              text_style_active1: activeIndex === 'delivery',
              text_style_active4: activeIndex === 'express',
              text_style_active7: activeIndex === 'shop'
            }" @click="handleClick(type_name1.key)">
						{{ type_name1.name }}
					</view>
				</view>
				<view class="" v-if="activeIndex === 'shop'" >
					<distribution v-if="
              mch_list[0].goods_list[0].product_type == 0 ||
              mch_list[0].goods_list[0].product_type == 4 ||
              mch_list[0].goods_list[0].product_type == 6
            " :address="address" :csa="1" :send_type_arr="send_type_arr" :isShop="isShop" ref="distribution"
						@toAddress="toAddress">
					</distribution>
					<view class="" v-if="is_store_mch">
						<view class="" v-if="show">
							<view class="addressNext">
								<view class="content_text">
									<text>自提点 :</text>
									<text class="ml20">{{ mdInfo.name }}</text>
								</view>
							</view>
							<view class="inDetail">
								<view class="" style="width: 104rpx; height: 104rpx; border-radius: 15rpx">
									<image style="width: 104rpx; height: 104rpx; border-radius: 15rpx" :src="mdInfo.logo"
										mode=""></image>
								</view>
								<view class="ml20">
									<view class="inDetailContent">
										{{ mdInfo.detail_address }}
									</view>
									<view class="inDetailColor">{{ mdInfo.distance }}</view>
								</view>
								<view class="content_txt inDetaiIcon" @click="goSelect">
									<view>{{ textName }}</view>
									<u-icon name="arrow-right" size="23rpx"></u-icon>
								</view>
							</view>
						</view>
						<view class="select_ziti"  @click="goSelect" v-if="product_type != 1" >
							<view class="">
								请选择自提点
							</view>
							<u-icon name="arrow-right" size="23rpx"></u-icon>
						</view>
					</view>
				</view>

				<!-- 下方内容  同城配送-->
				<view class="" v-if="activeIndex === 'delivery'">
					<distribution v-if="
              mch_list[0].goods_list[0].product_type == 0 ||
              mch_list[0].goods_list[0].product_type == 4 ||
              mch_list[0].goods_list[0].product_type == 6
            " :address="address" :send_type_arr="send_type_arr" :isShop="isShop" ref="distribution"
						@toAddress="toAddress">
					</distribution>
					<!-- 	<view class="sameCity">
						<view class="">
							配送时间
						</view>
						<view class="" style="display: flex;">
							<view class="" style="color:#F0250E;">
								立即配送
							</view>
							<view class="">
								<u-icon color="#B6B6B6" name="arrow-right"></u-icon>
							</view>
						</view>
					</view>
          <view class="deliveryMoney">
            配送费用 :
            <text style="color: #f0250e"
              >￥{{ all_price.rand_discount_price }}</text
            >
          </view> -->
				</view>

				<!-- 地址信息组件（送货上门） -->
				<view class="" v-if="activeIndex === 'express'">
					<distribution v-if="
              mch_list[0].goods_list[0].product_type == 0 ||
              mch_list[0].goods_list[0].product_type == 4 ||
              mch_list[0].goods_list[0].product_type == 6
            " :address="address" :send_type_arr="send_type_arr" :isShop="isShop" ref="distribution"
						@toAddress="toAddress">
					</distribution>
				</view>
			</view>
			</template>

			<view class="m-box serviceHomeForm" v-if="is_worker && worker">
				<view class="title">预约信息</view>

				<view class="serviceHomeItem" @click="$refs.servePopup.show = true">
					<view class="let"> 服务时间 </view>
					<view class="rig">
						{{ worker.default_date }}

						<i class="iconfont icon-arrow-right"></i>
					</view>
				</view>
				<view class="serviceHomeItem" v-if="worker.id">
					<view class="let"> 服务人员 </view>
					<view class="rig">
						<view class="workerInfo">
							<image :src="worker.logo" mode="aspectFill"></image>
							<view class="name">{{ worker.name }}</view>
						</view>
					</view>
				</view>
			</view>

			<template v-if="product_type === 2 && getTime">
				<view class="m-box">
					<view class="dateView">
						<view class="time">{{ getTime[0] }}
							<view v-if="getTime[1]">{{ getTime[1] }}</view>
						</view>
						<view class="and">{{ getTime[2] }}</view>
						<view class="and andLast">{{ getTime[3] }}</view>
					</view>
				</view>
			</template>

			<template v-if="product_type === 1 && getDate">
				<view class="m-box">
					<view class="dateView">
						<view class="time">{{ getDate[0].value }}
							<view v-if="isToday(getDate[0].date)">{{
                isToday(getDate[0].date)
              }}</view>
						</view>
						<view class="and totalNight">共{{ getDate[2] }}晚</view>
						<view class="time">{{ getDate[1].value }}
							<view v-if="isToday(getDate[1].date)">{{
                isToday(getDate[1].date)
              }}</view>
						</view>
					</view>
				</view>

				<view class="m-box">
					<view class="m-form">
						<view class="title">入住信息</view>

						<view class="form">
							<u-form :label-style="{ fontSize: '26rpx' }" ref="yuyueref" label-width="150">
								<u-form-item label="房间数" :border-bottom="false">
									<u-input disabled :value="getRoomNum + '间'" placeholder="" class="item_input"
										placeholder-style="font-weight: normal;"></u-input>
								</u-form-item>

								<view :class="['item', i === 0 ? 'first' : '']" v-for="(item, i) of addressList"
									:key="i">
									<u-form-item :label="'入住人'" :border-bottom="false" required>
										<u-input v-model="item.name" placeholder="请填写入住人姓名" class="item_input"
											placeholder-style="font-weight: normal;"></u-input>
									</u-form-item>
									<u-form-item label="身份证号" :border-bottom="false" required>
										<u-input v-model="item.idCard" @input="numInput(item.idCard, 'idCard', i)"
											placeholder="请填写身份证号码" class="item_input"
											placeholder-style="font-weight: normal;"></u-input>
									</u-form-item>
									<u-form-item :label="$t('clerk.phone')" :border-bottom="false" required>
										<u-input v-model="item.mobile" @input="numInput(item.mobile, 'mobile', i)"
											class="item_input" placeholder="请填写手机号"
											placeholder-style="font-weight: normal;" type="number"></u-input>
									</u-form-item>
								</view>
							</u-form>
						</view>
					</view>
				</view>
			</template>

			<view v-if="
          mch_list[0].goods_list[0].product_type != 0 &&
          mch_list[0].goods_list[0].product_type != 1 &&
          mch_list[0].goods_list[0].product_type != 3 &&
          mch_list[0].goods_list[0].product_type != 4 &&
          mch_list[0].goods_list[0].product_type != 6
        " class="yuyue-info m-box">
				<view class="yuyue-title"> {{ $t("order.info") }} </view>
				<view style="padding: 1rpx 0">
					<u-form :label-style="{ fontSize: '26rpx' }" ref="yuyueref" label-width="150">
						<u-form-item :label="$t('admin.concactPerson')" required :border-bottom="false">
							<u-input v-model="address.name" placeholder="请填写联系人姓名"></u-input>
						</u-form-item>
						<u-form-item :label="$t('clerk.phone')" required :border-bottom="false">
							<u-input v-model="address.mobile" placeholder="请填写联系人电话" type="number"></u-input>
						</u-form-item>
					</u-form>
				</view>
			</view>

			<!-- 多商品循环数据来源 -->

			<!-- 商品列表组件 -->
			<template v-if="mch_list">
				<good-list @setPayPrice="setPayPrice" @handleShop="handleShop"
					@updateDeliveryPrice="handleUpdateDeliveryPrice" @cass="cass" :sendTemplate="sendTemplate"
					:is_integral="is_integral" :address_id="address_id" :ref="'mch_info' + mchIndex"
					v-for="(mch, mchIndex) in mch_list" :index="mchIndex" :nameValue="nameValue" :key="mchIndex" :mch="{
            ...mch,
            yuyueData: optionsData[0].goods_list,
            location: locationData
          }" :submitParams="submitParams" :verify_card_id="verify_card_id" :mdInfo="mdInfo"
					:bookedInfo="getDate || getTime" :submitRequest="submitRequest" :product_type="product_type"
					:is_seckill="is_seckill" :worker_id="worker_id" :is_worker="is_worker"
					:activity_cut_price_order_id="activity_cut_price_order_id"
					:activity_wechat_room_id="activity_wechat_room_id"
					:mchList="mch_list"
					:showMd="is_store_mch"
					@changeSend="(e)=>handleClick(e)"></good-list>
			</template>

			<view class="m-box serviceHomeForm" v-if="is_worker && travel">
				<view class="title">
					<view class="titleLet">
						<i class="iconfont icon-prompt"></i>
						出行方式
					</view>

					<view class="titleRig">滴滴/出租</view>
				</view>

				<view class="des">
					全程共{{ travel.distance }}公里，出租出行收取来回车费，起步{{
            travel.starting_price
          }}元，超过1.00公里部分每公里{{ travel.additional_charge }}元
				</view>

				<view class="price">
					<view class="let">出行费用</view>
					<view class="rig">¥{{ travel.travelPrice }}</view>
				</view>
			</view>

			<view class="levelBox" v-if="mch_list && mch_list.next_level" @click="bayVip(mch_list.next_level)">
				<view class="levelBoxCon">
					<view class="levelLet">
						<view class="lv">
							<view class="lvBox">
								<image :src="asyncImgs.goods.goods4" mode="widthFix"></image>
								<view class="name">{{ mch_list.next_level.name }}</view>
							</view>
						</view>

						<view class="des">开通会员卡，立省{{ mch_list.next_level.diff_price }} 元</view>
						<view class="des2">天天0元购物，领大额会员红包</view>
					</view>

					<view class="levelRig">
						<view class="price">¥{{ mch_list.next_level.price }}/{{
                mch_list.next_level.name
              }}</view>
						<!-- <view class="oldPrice">¥29.9</view> -->
					</view>

					<view class="levelIcon">
						<i v-if="is_bug_level" class="iconfont icon-success-fill"></i>
						<i v-else class="iconfont icon-xuanzekuangmoren"></i>
					</view>
				</view>
			</view>

			<!-- 订单明细组件 -->
			<goodsfreight :all_price="all_price" @handleBalance="handleBalance" @handleIntegral="handleIntegral" :is_integral="is_integral"
				:is_worker="is_worker" :mchList="mch_list" :hasInvoice="hasInvoice"></goodsfreight>

			<!-- 积分使用规则 -->

			<!--     <u-alert-tips
        v-if="integration"
        type="warning"
        title="积分使用规则"
        :description="integration"
      ></u-alert-tips> -->

			<invoice ref="invoice" @callback="invoiceCallback" v-if="invoice_is_open" :invoiceConf="invoiceConf">
			</invoice>

			<template v-if="show_saas_alliance_coupon">
				<!-- 本单可返联盟券 -->
				<view class="unionAll" v-if="parseInt(unionAll) || parseInt(unionDis)">
					<img src="../components/images/coupon2.png" alt=""
						style="width: 300rpx; height: 60rpx; transform: translateX(-24rpx)" />
					<div class="coupon-dis">
						<p>联盟券最高可抵扣</p>
						<view class="dis-money">- ￥{{ unionDis ? unionDis : parseInt(unionDis) }}</view>
					</div>
					<div class="coupon-back">
						<span>券</span>
						<p>
							本单最高
							<span>可以获得{{ unionAll }}联盟券</span>
						</p>
					</div>
				</view>
			</template>

			<!-- 支付类型 -->
			<!-- <paySelect :payType="payType" @handleSelect="showPayPopup"></paySelect> -->

			<!-- 支付类型选择弹框 -->
			<!-- <payWayPopup
        ref="pay_type_list"
        :pay_type_list="pay_type_list"
        :payType="payType"
        @payTypeSelect="payTypeSelect"
      ></payWayPopup> -->

			<!-- 支付类型选择弹框 -->
			<newPayWayPopup :showPopup="showPayWayPopup" :payWayList="pay_type_list" :current="payType"
				@payTypeSelect="payTypeSelect" @closePopup="showPayWayPopup = false"></newPayWayPopup>

			<!-- 提交订单组件 -->
			<suborder :address="address" @submitOrder="submitOrder" :pay_price="submitData.pay_price"
				:mch_list="mch_list" :nameValue="nameValue"></suborder>

			<!-- 是否使用积分抵扣弹框 -->
			<integralUsePopup ref="integralUsePopup" :price="integralPrice" :useIntegral="useIntegral"
				@confirm="isUseIntegral" v-if="!is_integral"></integralUsePopup>

			<!-- 是否使用余额抵扣弹框 -->
			<balanceUsePopup ref="balanceUsePopup" :price="balance" :useBalance="useBalance"
				@confirm="isUseBalance" v-if="!is_integral"></balanceUsePopup>


			<!-- 是否使用现金抵扣积分弹窗 -->
			<u-popup v-model="showCashDis" mode="center" border-radius="24">
				<view class="cashWarn">
					<view class="title">订单提示</view>
					<view class="content">您当前的{{
              stores.integral_name
            }}不足，继续提交可以用现金抵扣支付</view>
					<view class="btns">
						<text @click="showCashDis = false">取消</text>
						<text @click="submitOrder">继续提交</text>
					</view>
				</view>
			</u-popup>

			<u-popup v-model="notListPop" mode="center" border-radius="24">
				<view class="notListPop">
					<view class="title">订单提示</view>

					<scroll-view scroll-y style="max-height: 500rpx">
						<!-- <template v-for="item of notListPic"> -->
						<view class="item" :key="i" v-for="(citem, i) of notListPic">
							<view class="img">
								<image class="item-gooddetails-left" :src="citem.goods_pic" mode="aspectFit"></image>
							</view>

							<view class="txt">
								<view class="name">{{ citem.goods_name }}</view>

								<view class="sku">
									<text style="margin-right: 6px" v-for="(attr, attrIndex) in citem.attr_list"
										:key="attrIndex">
										{{ attr.attr_group_name }}:{{ attr.attr_name }}
									</text>
								</view>

								<view class="itemFd">
									<view class="price">
										¥
										<text>{{ citem.level_price | integer }}</text>
										{{ citem.level_price | decimals }}
									</view>
									<view class="num">×{{ citem.num }}</view>
								</view>
								<view class="error">
									{{ citem.msg }}
								</view>
							</view>
						</view>
						<!-- </template> -->
					</scroll-view>

					<view class="btn">
						<view @click="$utils.goBack()">返回上一级</view>
						<view class="on" @click="removePic" v-if="isCart">确认移除</view>
						<view class="on" @click="notListPop = false" v-else>确定</view>
					</view>
				</view>
			</u-popup>

			<servePopup ref="servePopup" v-if="worker" :serveData="{
          service_book: {
            data: worker.time
          }
        }" @submit="(e) => (worker.default_date = e)"></servePopup>
		</view>
	</view>
	<Shenhe v-else-if="shenheStatus == 1"></Shenhe>
</template>

<script>
	import Shenhe from "@/components/shenhe/shenhe";
	import distribution from "../components/order-submit/distribution.vue";
	import goodList from "../components/order-submit/goodlist.vue";
	import invoice from "../components/order-submit/invoice.vue";
	import goodsfreight from "../components/order-submit/goodsfreight.vue";
	import paymethod from "../components/order-submit/paymethod.vue";
	import suborder from "../components/order-submit/suborder.vue";
	import payWayPopup from "../components/pay-order/pay-way-popup.vue";
	import newPayWayPopup from "@/components/popups/payWayPopup.vue";
	import paySelect from "../components/pay-order/pay-select.vue";
	import integralUsePopup from "../components/order-submit/integralUsePopup.vue";
	import balanceUsePopup from "../components/order-submit/balanceUsePopup.vue";
	import {
		cutPriceOrderCreate
	} from "@/api/marketing/curPrice";

	import WxOpenSubscribe from "../components/wx-open-subscribe";
	import servePopup from "./components/serve-popup.vue";

	export default {
		components: {
			Shenhe,
			distribution,
			goodList,
			invoice,
			goodsfreight,
			paymethod,
			suborder,
			payWayPopup,
			paySelect,
			newPayWayPopup,
			integralUsePopup,
			balanceUsePopup,
			WxOpenSubscribe,
			servePopup
		},

		data() {
			return {
				change_shop: null,
				activeIndex: "express", //默认选择配送方式
				submitRequest: null, // 传参
				optionsData: null, //传参
				pay_type_list: null, // 支付方式
				address: {
					name: "",
					mobile: ""
				}, // 收货地址
				mch_list: null, // 初始化数据,订单商家列表
				submitData: null, // 提交地址
				show_address: false, // 是否展示收货地址
				pay_price: 0, // 支付价格
				all_price: null,
				tamplate_id: [],
				send_type_arr: [],
				payType: "", // 支付方式
				yuyueForm: null, //预约表单
				isShop: false, //是否选有有门店自提商品
				shopList: [], //自提门店列表
				locationData: {}, // 定位信息
				submitParams: "", // 原始提交参数
				is_delivery: 0, // 是否同城配送
				delivery_price: 0, // 同城配送费用
				show_page: false, //页面是否显示
				verify_card_id: 0, //卡劵id
				showPayWayPopup: false,
				useIntegral: true,
				useBalance: true,
				integralPrice: "0",
				sendTemplate: "",
				balancePrice: "0",
                is_store_mch:true,
				mdInfo: null, // 自提点信息
				showCashDis: false, // 是否显示现金抵扣弹窗
				product_type: 0,

				addressList: [], // 酒店预约地址列表
				notList: [],
				notListPic: [],

				notListPop: false,
				isCart: false,
				pt_number: "",
				is_bug_level: "",
				activity_cut_price_id: "", // 生成砍价订单
				activity_cut_price_order_id: "", // 预览砍价订单参数
				unionAll: "",
				unionDis: "",
				is_seckill: "",
				show_saas_alliance_coupon: false,
				worker_id: "",
				is_worker: "",
				worker: null,
				travel: null,
				activity_wechat_room_id: "", //群活动id

				outParams: null,
				integration: "",

				invoiceConf: null,
				invoice_is_open: 0,
				hasInvoice: false,
				balance: 0, // 商品抵扣余额
				ListMassage: {},
				// diy定制
				type_diy: null,
				type_color_diy: "#f0250e",
				type_name1: null,
				type_name2: null,
				type_name3: null,
				// 支付方式名称
				pmyName: null,
				nameValue: "",
				newTemplate: "",
				textName: "切换",

				traceId: "",
				address_id: 0,
				show: false,
                is_fugou: 0,
			};
		},
		mounted() {
			this.getDiySystemPages();
		},

		onLoad(options) {
			this.change_shop = uni.getStorageSync("change_shop");
			if (this.change_shop != 1) {
				this.textName = "";
			}
			if (uni.getStorageSync("storeMdData")) {
				this.show = true
			} else {
				this.show = false
			}

			uni.setNavigationBarTitle({
				title: this.$t("title.orderSubmit")
			});
            
            if (options.is_fugou) {
                this.is_fugou = options.is_fugou;
            }

			// #ifdef MP-ALIPAY
			if (options.outItemId) {
				this.outParams = {
					outItemId: options.outItemId,
					outSkuId: options.outSkuId,
					count: options.count
				};
				return;
			}
			// #endif

			// 拼团id
			if (options.pt_number) this.pt_number = options.pt_number;
			if (options) {
				this.submitParams = options.submit;
				this.submitRequest = options.submit;
				this.optionsData = JSON.parse(options.submit);
				if (this.optionsData[0].product_type) {
					this.product_type = parseInt(this.optionsData[0].product_type);
				}
				if (options.is_delivery && options.is_delivery == 1) {
					this.is_delivery = 1;
				}
				if (options.verify_card_id) {
					this.verify_card_id = options.verify_card_id;
				}
				if (options.activity_cut_price_id) {
					this.activity_cut_price_id = options.activity_cut_price_id;
				}
				if (options.activity_cut_price_order_id) {
					this.activity_cut_price_order_id = options.activity_cut_price_order_id;
				}

				if (options.is_seckill) {
					this.is_seckill = options.is_seckill;
				}

				if (options.is_worker) this.is_worker = options.is_worker;
				if (options.worker_id) this.worker_id = options.worker_id;

				// 群活动id
				this.activity_wechat_room_id = options.activity_wechat_room_id || "";
			}

			// #ifdef MP-WEIXIN
			wx.checkBeforeAddOrder({
				success: (res) => {
					try {
						const {
							errcode,
							traceId
						} = res.data;
						if (!errcode) {
							this.traceId = traceId;
						}
					} catch (error) {}
				}
			});
			// #endif
		},
		async onShow() {
			if (uni.getStorageSync("storeMdData")) {
				this.show = true
			} else {
				this.show = false
			}
			try {
				// #ifdef MP-ALIPAY
				let {
					outParams
				} = this;
				if (outParams) {
					let params = {
						_filter_func: "_filter_func_ali_goodsDetailPlugin",
						data: {
							...outParams
						}
					};
					const res = await this.$allrequest.order.filterMchList({
						mch_list: JSON.stringify(params)
					});
					if (!res.code) {
						let str = JSON.stringify(res.data);
						this.submitParams = str;
						this.submitRequest = str;
						this.optionsData = res.data;
						this.product_type = res.data[0].product_type;
					}
				}
				// #endif

				// 是否是砍价订单
				let {
					activity_cut_price_id
				} = this,
				goods_id = this.optionsData[0].goods_list[0].goods_id;

				if (activity_cut_price_id) {
					this.getPutPriceOrder({
						activity_id: activity_cut_price_id,
						goods_id
					});
					return;
				}
				this.getLocation();
				this.getuserinfo();
			} catch (error) {
				this.$utils.showModal(
					"提示",
					error,
					false,
					() => {
						this.$utils.goBack();
					},
					() => {}
				);
			}
		},
		filters: {
			integer(data) {
				let end = data.indexOf(".");
				if (end !== -1) {
					data = data.substr(0, end);
				}
				return data;
			},
			decimals(data) {
				let end = data.indexOf(".");
				data = data.substr(end, 3);
				if (end === -1) {
					data = "";
				}
				return data;
			}
		},
		watch: {
			//监听不能输入中文
			// addressList: {
			// 	handler(newArray) {
			// 		for (let i in newArray) {
			// 			newArray[i]['idCard'] = newArray[i]['idCard'].replace(/[^\w\/]/ig,'');
			// 		}
			// 		return newArray;
			// 	},
			// 	deep: true,
			// 　	immediate: false
			// }
		},
		methods: {
			cass(val) {
				this.newTemplate = val;
			},
			// 点击切换自提点
			goSelect() {
				if (this.change_shop == 1) {
					uni.setStorageSync("addressActiveIndex", this.activeIndex);

					uni.navigateTo({
						url: "/goods/selectSelfPickup/selectSelfPickup"
					});
				} else {
					return;
				}
			},
			// 点击切换配送方式
			handleClick(item) {
				this.nameValue = item;
				this.activeIndex = item;
				this.sendTemplate = item;

				this.$nextTick(()=>{
					this.checkBuyer();
				})
			},
			// 点击自提配送切换地址
			toAddress() {
				uni.setStorageSync("addressActiveIndex", this.activeIndex);

				uni.navigateTo({
					url: "/user/my/addressmanage?is_order=1"
				});
			},
			// 选择支付方式
			selectPymen() {
				this.showPayWayPopup = true;
			},
			// 获取diy系统页面配置数据
			getDiySystemPages() {
				this.$allrequest.diyNew.getDiySystemPages({}, true).then((res) => {
					if (!res.code) {
						let list = res.data.list;
						let data = {};
						if (!list.length) return;
						list.forEach((d) => {
							d.template = JSON.parse(d.template);
							if (d.template.system_type == "orderPreview") {
								data = d;
								// 判断diy配送的自定义
								this.type_diy = data.template.templates[1].params.type;
								// 判断diy自定义背景色
								this.type_color_diy =
									data.template.templates[1].moduleCss.backgroundColor;
							}
						});
					}
				});
			},

			isofficial: function() {
				// #ifdef H5
				if (this.$utils.isWechat()) {
					return true;
				}
				// #endif
				return false;
			},
			numInput: function(value, type, index) {
				if (type === "idCard") {
					value = value.replace(/[\W]/g, "");
					if (value.length > 18) {
						value = value.slice(0, 18);
					}
				}
				if (type === "mobile") {
					value = value.replace(/[^\d]/g, "");
					if (value.length > 12) {
						value = value.slice(0, 12);
					}
				}
				this.$nextTick(() => {
					this.addressList[index][type] = value;
				});
				//this.$forceUpdate()
			},
			// 更新同城配送费
			handleUpdateDeliveryPrice: function(e) {
				this.delivery_price = e;
				this.setPayPrice();
			},
			// 获取定位
			async getLocation() {
				const res = await this.$store.dispatch("getLocation");
				if (res) {
					let {
						longitude,
						latitude
					} = res;
					this.locationData.longitude = longitude;
					this.locationData.latitude = latitude;
				}
				await this.getShopList();
				await this.getOrder();
			},

			// 获取自提门店列表
			async getShopList() {
				let query = {
					page: 1,
					longitude: this.locationData.longitude,
					latitude: this.locationData.latitude
				};
				const res = await this.$allrequest.shop.nearby(query);
				if (res.code != 0) return;
				this.shopList = res.data.list;
			},

			// 获取订单数据
			async getOrder() {
				var address_id = 0,
					address = uni.getStorageSync("SELECT_ORDER_ADDRESS");
				if (address) {
					address_id = JSON.parse(address).id;
					uni.removeStorageSync("SELECT_ORDER_ADDRESS");
					// 判断是否有选中同城配送，需重新获取价格，另外需携带原单号
					this.mch_list.forEach((item, i) => {
						let goodsListDom = this.$refs[`mch_info${i}`][0];
						if (goodsListDom.mchItemData.send == "delivery") {
							goodsListDom.$refs.timePopup.handleConfirm();
						}
					});
				}
				this.address_id = address_id;

				var that = this;
                  console.log('主页面this.submitRequest',this.submitRequest)
				var params = {
					mch_list: this.submitRequest,
					address_id: address_id,
					_from: "mini",
					verify_card_id: this.verify_card_id,
					longitude: uni.getStorageSync("locationData").longitude || '',
					latitude: uni.getStorageSync("locationData").latitude || ''
				};

				// 拼团接口及拼团id
				let requestName = "submitPreview";
				if (this.pt_number) {
					params.pt_number = this.pt_number;
					requestName = "ptSubmitPreview";
				}
				if (this.activity_cut_price_order_id) {
					params.activity_cut_price_order_id = this.activity_cut_price_order_id;
				}

				if (this.is_seckill) {
					params.is_seckill = this.is_seckill;
				}

				if (this.worker_id) params.worker_id = this.worker_id;
				if (this.is_worker) params.is_worker = this.is_worker;

				// 群活动id
				this.activity_wechat_room_id &&
					(params.activity_wechat_room_id = this.activity_wechat_room_id);

				// #ifdef APP-PLUS
				params._from = "app";
				// #endif

				this.$allrequest.order[requestName](params, true)
					.then((res) => {
						if (res.code == 0) {
							if (this.product_type === 1) {
								let num = res.data.mch_list[0].goods_list[0].num,
									addressList = [];

								for (let i = 0; i < num; i++) {
									addressList.push({
										name: "",
										mobile: "",
										idCard: ""
									});
								}

								this.addressList = addressList;
							}

							// 赋值支付方式列表
							this.pay_type_list = res.data.pay_type_list;
							this.payType = -1;
							// 设置默认支付方式
							this.address = res.data.address;
							this.unionAll = (+res.data.send_price).toFixed(2);
							this.unionDis = (+res.data.take_price).toFixed(2);
							// this.balance = (+res.data.mch_list[0].goods_list[0].balance).toFixed(2);
							let balance = 0;
							if (res.data.mch_list && res.data.mch_list.length > 0 && res.data.mch_list[0]
								.goods_list && res.data.mch_list[0].goods_list.length > 0) {
								for (let mchItem of res.data.mch_list) {
									if (mchItem.goods_list && mchItem.goods_list.length > 0) {
										for (let goodsItem of mchItem.goods_list) {
											if (goodsItem.balance != null) {
												balance += parseFloat(goodsItem.balance);

											}
										}
									}
								}
								this.balance = balance;
							}
							var mch_list = JSON.parse(JSON.stringify(res.data.mch_list));
							mch_list.forEach((el) => {
								el.integral = {
									forehead: Math.floor(el.integral.forehead),
									forehead_integral: Math.floor(el.integral.forehead_integral)
								};

								el.goods_list.forEach((e) => {
									e.integral = {
										forehead: Math.floor(e.integral.forehead),
										forehead_integral: Math.floor(e.integral
											.forehead_integral)
									};
								});
							});

							this.mch_list = mch_list;
							// 判断diy自定义名字

							let str = JSON.parse(JSON.stringify(this.mch_list[0].send_type));

							switch (this.mch_list[0].product_type) {
								case 3:
									str = ['online']
									break;

								default:
									for (let i = 0; i < str.length; i++) {
										if (str[i] == this.mch_list[0].diy_send_type[2].key) {
											this.type_name1 = this.mch_list[0].diy_send_type[2];
										} else if (str[i] == this.mch_list[0].diy_send_type[0].key) {
											this.type_name2 = this.mch_list[0].diy_send_type[0];
										} else if (str[i] == this.mch_list[0].diy_send_type[1].key) {
											this.type_name3 = this.mch_list[0].diy_send_type[1];
										}
									}
								break;
							}

							// 销售规则
							this.checkBuyer();

							let arr = new Array(mch_list.length).fill(false);
							this.send_type_arr = arr;
							// 生成提交数据
							this.submitData = {
								address_id: res.data.address ? res.data.address.id : 0,
								mch_list: mch_list,
								use_integral: 0,
								use_balance: 0,
								payment: -1,
								data:JSON.stringify(mch_list)
							};
							this.tamplate_id = res.data.template_id;
							this.mdInfo = res.data.md_info;

							if (this.is_delivery == 1 || this.activeIndex == "delivery") {
								let submitOrderData = JSON.parse(JSON.stringify(this.submitData));
								submitOrderData.mch_list = JSON.stringify(
									submitOrderData.mch_list
								);

								this.$allrequest.order
									.preSubmitOrder(submitOrderData, true)
									.then((preRes) => {
										if (preRes.data.resultcode == 0) {
											this.delivery_price = preRes.data.fee;
										} else {
											uni.showToast({
												title: this.$t("order.fail"),
												duration: 2000
											});
										}
										setTimeout(function() {
											that.setPayPrice();
										}, 500);
									});
							} else {
								setTimeout(function() {
									that.setPayPrice();
								}, 500);
							}
							this.show_page = true;

							// 优化地址配送费的问题
							this.$nextTick(() => {
								let ref = this.$refs;
								for (let i in ref) {
									if (i.indexOf("mch_info") !== -1) {
										ref[i].forEach((el) => {
											if (el.screeningDistribution) {
												el.screeningDistribution();
											}
										});
									}
								}
							});
							this.show_saas_alliance_coupon = res.data.show_saas_alliance_coupon;

							if (res.data) {
								let {
									worker,
									travel,
									integral
								} = res.data;
								if (worker) this.worker = worker;
								if (travel) this.travel = travel;
								if (integral) this.integration = integral.integration;

								this.invoiceConf = res.data.invoiceConf;
								this.invoice_is_open = res.data.invoice_is_open;
							}

							if ([1242, 1243, 1245].includes(uni.getStorageSync("scene"))) {
								this.handleClick("");

								this.$nextTick(() => {
									setTimeout(() => {
										this.handleClick("delivery");
									}, 1000);
								});
							} else {
								// 避免切换地址后重新初始化配送方式
								if (uni.getStorageSync("addressActiveIndex")) {
									this.handleClick(uni.getStorageSync("addressActiveIndex"));
									uni.removeStorageSync("addressActiveIndex");
									return;
								}

								this.handleClick("");

								this.$nextTick(() => {
									setTimeout(() => {
										this.handleClick(str[0]);
									}, 1000);
								});
							}
						} else {
							this.$utils.showModal(
								"提示",
								res.msg,
								false,
								() => {
									this.$utils.goBack();
								},
								() => {}
							);
						}
					})
					.catch(() => {
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							});
						}, 2500);
					});
			},

			// 获取订单数据
			async getPutPriceOrder(param) {
				var address_id = 0,
					address = uni.getStorageSync("SELECT_ORDER_ADDRESS");
				if (address) {
					address_id = JSON.parse(address).id;
					uni.removeStorageSync("SELECT_ORDER_ADDRESS");
				}

				var params = {
					mch_list: this.submitRequest,
					address_id: address_id,
					_from: "mini",
					verify_card_id: this.verify_card_id,
					...param
				};

				// #ifdef APP-PLUS
				params._from = "app";
				// #endif
				cutPriceOrderCreate(params, true)
					.then((res) => {
						if (res.code == 0 && res.data) {
							uni.redirectTo({
								url: `/marketing/curPrice/active/index?id=${res.data}`
							});
						} else {
							this.$utils.showModal(
								"提示",
								res.msg,
								false,
								() => {
									this.$utils.goBack();
								},
								() => {}
							);
						}
					})
					.catch(() => {
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							});
						}, 2500);
					});
			},
			// 获取销售规则
			async checkBuyer() {
				// if (this.address && this.address.id) {
				if(!this.nameValue) return;

				let address_id = this.address ? this.address.id || "" : "",
					goods_ids = [],
					{
						mch_list,
						// isShop
					} = this;

				mch_list.forEach((el) => {
					if (el.goods_list && el.goods_list.length) {
						el.goods_list.forEach((cel) => {
							if (goods_ids.indexOf(cel.id) === -1) {
								goods_ids.push({
									goods_id:cel.id,
									num:cel.num
								});
							}
						});
					}
				});

				const res = await this.$allrequest.order.checkBuyer({
						address_id,
						goods_ids,
						isShop:this.nameValue == 'express'?false:true
					},
					true
				);
				if (!res.code) {
					let {
						data
					} = res,
					notList = [],
						notListPic = [],
						isCart = false;

					for (let i in data) {
						if (data[i] && !data[i].status) {
							notList.push({
								goods_id: parseInt(i),
								msg: data[i].msg
							});
						}
					}

					mch_list.forEach((el) => {
						if (el.goods_list && el.goods_list.length) {
							el.goods_list.forEach((cel) => {
								let index = notList.map((el) => el.goods_id).indexOf(cel.id);
								if (index !== -1) {
									cel.msg = notList[index].msg;
									notListPic.push(cel);
								}
							});
						}
					});

					if (mch_list[0].goods_list[0].cart_id) {
						isCart = true;
					}

					this.notList = notList;
					this.notListPic = notListPic;
					this.isCart = isCart;

					if (notListPic.length) {
						this.notListPop = true;
					}else{
						this.notListPop = false;
					}
				}
			},

			async removePic() {
				let {
					mch_list,
					notList,
					submitRequest
				} = this,
				cart_id_list = [];

				mch_list.forEach((el) => {
					if (el.goods_list && el.goods_list.length) {
						el.goods_list.forEach((cel) => {
							if (notList.map((el) => el.goods_id).indexOf(cel.goods_id) !== -1) {
								cart_id_list.push(cel.cart_id);
							}
						});
					}
				});

				submitRequest = JSON.parse(submitRequest);
				submitRequest[0].goods_list = submitRequest[0].goods_list.filter((el) => {
					return cart_id_list.indexOf(el.cart_id) === -1;
				});

				submitRequest = JSON.stringify(submitRequest);
				const res = await this.$allrequest.goodscart.deleteCart({
						cart_id_list
					},
					true
				);

				if (!res.code) {
					this.optionsData = JSON.parse(submitRequest);
					this.submitRequest = submitRequest;
					this.$utils.showModal(
						"提示",
						"移除成功！",
						false,
						() => {
							this.notListPop = false;
							this.getOrder();
						},
						() => {}
					);
				}
			},
			setPayPrice(e) {
				var pay_price = 0; // 支付金额
				var all_express_price = 0; // 配送费
				var all_goods_price = 0; // 商品金额
				var all_coupon_price = 0; // 优惠券金额
				var all_integral_price = 0; // 积分抵扣
				var all_balance_price = 0; // 余额抵扣
				var all_integral = 0; // 积分商品使用多少积分
				var submitData = this.submitData;
				let balance = 0;
				// 循环商家列表
				this.isShop = false; //默认没有自提  如果有则变为true
				this.mch_list.forEach((mch_info, index) => {

					// 获取当前商家
					var mch = this.$refs["mch_info" + index][0] ?
						this.$refs["mch_info" + index][0] :
						this.$refs["mch_info" + index];

					// 当前商家订单价格
					var mch_price = mch.mchItemData.level_price - 0;
					// 合计金额
					all_goods_price += mch.mchItemData.level_price - 0;
                   console.log('mch.mchItemData',mch.mchItemData)
				   // 判断订单中是否有入驻商订单，有的话隐藏自提配送提示
				   if(mch.mchItemData&&mch.mchItemData.mch_id>0){
					    this.is_store_mch= false
				   }
					// 判断是否使用快递计算快递价格,  判断是否有门店自提.
					if (mch.mchItemData.send == "shop") {
						// 用于提示 已选自提
						this.isShop = true;
					} else if (mch.mchItemData.send == "express") {
						// 计算订单金额
						mch_price += mch.mchItemData.express_price - 0;
						// 计算快递金额
						all_express_price += mch.mchItemData.express_price - 0;
					}
					if (mch_info.name == `${this.stores.integral_name}商品`) {
						let integral = mch.mchItemData.goods_list.map((item) => {
							return item.integral_price;
						});
						integral.forEach((item) => {
							all_integral += item - 0;
						});
					} else {
						// 判断是否使用优惠券
						if (
							mch.mchItemData.picker_coupon &&
							mch.mchItemData.picker_coupon?.sub_price
						) {
							// 商家订单金额大于优惠券
							if (mch_price >= mch.mchItemData.picker_coupon.sub_price) {
								mch_price -= mch.mchItemData.picker_coupon.sub_price;
								all_coupon_price += mch.mchItemData.picker_coupon.sub_price;
							}
						}

						// 使用积分抵扣
						if (this.useIntegral && mch.mchItemData.integral.forehead > 0) {
							all_integral_price += mch.mchItemData.integral.forehead;
							mch_price -= mch.mchItemData.integral.forehead;
							this.integralPrice = all_integral_price;
						}
						// 使用余额抵扣

						if (this.useBalance && mch.mchItemData.goods_list.length > 0) {
							for (let goodsItem of mch.mchItemData.goods_list) {
								if (goodsItem.balance != null) {
									balance += parseFloat(goodsItem.balance);
								}
							}
							all_balance_price = balance;
							// mch_price -= balance;
							this.balancePrice = balance;
							this.balance = balance;

						}
					}

					if (this.is_worker) {
						pay_price += mch_info.travel_price;
					}

					// 支付金额
					pay_price += mch_price;

					if (this.hasInvoice) {
						pay_price += parseFloat(mch_info.tax_price);
					}
				});

				// 服务预约计算商品金额
				if (this.mch_list[0].goods_list[0].product_type == 2) {
					all_goods_price =
						this.optionsData[0].list.price *
						this.optionsData[0].goods_list[0].num;
					pay_price =
						all_goods_price -
						all_express_price -
						all_coupon_price -
						all_integral_price;
				}
				// 酒店预约计算商品金额
				else if (this.mch_list[0].goods_list[0].product_type == 1) {
					// all_goods_price =
					// 	all_goods_price * (this.optionsData[0].list.length - 1);
					// this.optionsData[0].list.forEach((item) => {
					//   all_goods_price += parseFloat(item.price);
					// });
					pay_price =
						all_goods_price -
						all_express_price -
						all_coupon_price -
						all_integral_price;
				}

				pay_price += this.delivery_price; // 加上同城配送费用

				if (this.verify_card_id) {
					if (pay_price <= 0) pay_price = 0;
				} else {
					// if (pay_price <= 0) pay_price = 0.01;
				}

				if (this.mch_list && this.mch_list[0].next_level && this.is_bug_level) {
					pay_price = parseFloat(this.mch_list[0].next_level_price);
				}

				if (this.mch_list && this.mch_list[0].rand_discount_price > 0) {
					pay_price -= this.mch_list[0].rand_discount_price;
				}

				if(this.unionDis) pay_price -= parseFloat(this.unionDis)

				this.pay_price = pay_price.toFixed(2);
				submitData.payment = this.payType;
				this.submitData.pay_price = (this.pay_price - this.unionDis).toFixed(2);
				if(!this.useBalance){
					this.submitData.pay_price = this.submitData.pay_price;
					this.balancePrice = '0';
				}else{
					this.submitData.pay_price = (parseFloat(this.pay_price) - parseFloat(this.balance)).toFixed(2);
				}
				if (parseFloat(this.submitData.pay_price) <= 0) {
					this.submitData.pay_price = "0.00";
				}

				if (this.is_worker) {
					all_goods_price += parseFloat(this.mch_list[0].final_price);
				}

				this.all_price = {
					all_delivery_price: this.delivery_price, // 同城配送费用
					all_express_price: all_express_price, //配送费用
					all_goods_price: parseFloat(all_goods_price).toFixed(2), // 商品费用
					all_coupon_price: all_coupon_price, //优惠券费用
					all_integral_price: all_integral_price, //积分费用
					all_balance_price: this.balance, //余额费用
					goods_type: this.mch_list[0].goods_list[0].product_type,
					all_integral: all_integral, // 积分商品使用了多少积分
					union_dis: this.unionDis, //联盟全抵扣金额
					all_balance: this.balancePrice, //商品使用了多少余额
					union_all: this.unionAll, //可返联盟券
					final_price: this.mch_list[0].final_price, // 尾款费用
					pre_price: this.mch_list[0].pre_price, // 定金费用
					travel_price: this.mch_list[0].travel_price, // 出行费用
					rand_discount_price: this.mch_list[0].rand_discount_price ,// 随机立减
                    pay_price: this.submitData.pay_price, // 支付金额
				};

				if (this.hasInvoice) {
					this.all_price.tax_price = this.mch_list[0].tax_price;
				}
				return;
			},

			// 提交订单
			submitOrder() {
				this.$u.throttle(async () => {
					let {
						product_type,
						addressList,
						address,
						notListPic
					} = this,
					regIdNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
						regMobile = new RegExp("^1[23456789]\\d{9}$");

					if (notListPic.length) {
						this.notListPop = true;
						return;
					}

					if (product_type === 1) {
						if (!addressList.every((el) => el.name)) {
							this.$utils.toast("请填写入住人姓名~");
							return;
						}

						if (!addressList.every((el) => el.idCard)) {
							this.$utils.toast("请填写身份证号~");
							return;
						}

						if (addressList.some((el) => !regIdNo.test(el.idCard))) {
							this.$utils.toast("请填写正确的身份证号~");
							return;
						}

						if (!addressList.every((el) => el.mobile)) {
							this.$utils.toast("请填写联系电话~");
							return;
						}

						if (addressList.some((el) => !regMobile.test(el.mobile))) {
							this.$utils.toast("请填写正确的联系电话~");
							return;
						}
					} else if (product_type === 2) {
						if (!address.name) {
							this.$utils.toast("请填写联系人姓名~");
							return;
						}

						if (address.mobile === "") {
							this.$utils.toast("请填写联系电话~");
							return;
						}

						if (!regMobile.test(address.mobile)) {
							this.$utils.toast("请填写正确的联系电话~");
							return;
						}
					}

					if (product_type === 6 && !address)
						return this.$utils.toast("请填写收货地址~");

					if (this.mch_list[0].goods_list[0].product_type == 4) {}
					let arr = [];
					for (let i = 0; i < this.mch_list.length; i++) {
						// 获取每个商家订单数据
						let goodsListPage = this.$refs["mch_info" + i][0];
						let mchItemData = JSON.parse(
							JSON.stringify(goodsListPage.mchItemData)
						);
						// let use_integral = goodsListPage.use_integral;
						let use_integral = this.useIntegral;
						let use_balance = this.useBalance;
						let delGoodsList = goodsListPage.delGoodsList;

						// 表单验证
						try {
							if (!mchItemData.send) throw this.$t("order.method");
							mchItemData.goods_list.forEach((good) => {
								// 预约商品验证
								if (good.product_type != 0 && good.product_type != 3) {
									if (!this.address.name || !this.address.mobile)
										throw this.$t("order.fillInfo");
								} else {
									// 普通商品地址校验
									if (
										!this.isShop &&
										this.submitData.address_id == 0 &&
										good.product_type != 3
									) {
										throw this.$t("order.fillAddress");
									}
								}

								// 验证后台自定义表单
								good.form.list.forEach((item) => {
									if (item.required == 1 && item.default.length == 0) {
										throw item.tip;
									}
								});
							});
						} catch (error) {
							this.$utils.toast(error);
							return;
						}

						if (delGoodsList.length) {
							await new Promise((resolve, reject) => {
								uni.showModal({
									title: this.$t("order.prompt"),
									content: this.$t("order.addCart"),
									success(res) {
										if (res.confirm) {
											return resolve();
										} else if (res.cancel) {
											return reject();
										}
									}
								});
							});
						}

						//    没有留言加留言
						if (!mchItemData.remark) {
							mchItemData.remark = "";
						}
						// 是否开启积分扣除
						if (use_integral) {
							mchItemData.use_integral = 1;
						} else {
							mchItemData.use_integral = 0;
						}
						// 是否开启余额扣除
						if (use_balance) {
							mchItemData.use_balance = 1;
						} else {
							mchItemData.use_balance = 0;
						}
						// 门店自提数据修改
						mchItemData.goods_list = mchItemData.goods_list.map((good) => {
							//同城自提
							if (good.send == "shop") {
								good.shop_id = good.shop.id;
							}
							return good;
						});

						// 优惠券数据对象改数组,后台要求
						mchItemData.picker_coupon = mchItemData.picker_coupon;
						arr.push(mchItemData);
					}

					// 预约订单数据处理,修改预约独有数据
					if (arr[0].goods_list[0].product_type == 1) {
						let addressList = JSON.parse(JSON.stringify(this.addressList));
						if (!addressList.every((el) => el.idCard && el.mobile && el.name)) {
							this.$utils.toast("请完善入住信息");
							return;
						}

						let list = JSON.parse(JSON.stringify(this.optionsData[0].list));
						list.splice(list.length - 1, 1);
						// 设置后台商品定义表单内容
						arr[0].goods_list[0].book = list;
						// 设置预约收货人
						arr[0].book_info = addressList;
					} else if (arr[0].goods_list[0].product_type == 2) {
						// 设置后台商品定义表单内容
						arr[0].goods_list[0].service = this.optionsData[0].list;
						// 设置预约收货人
						arr[0].book_info = {
							name: this.address.name,
							mobile: this.address.mobile
						};
					}

					this.submitData.mch_list = JSON.parse(JSON.stringify(arr));
					// 如果订单中有快递订单，则要走订阅消息后，下单
					let haveExpress = this.submitData.mch_list.some((d) => {
						let flag = d.goods_list.some((i) => {
							return d.send == "express" || "shop";
						});
						return flag;
					});
					this.template_id = this.newTemplate;

					if (haveExpress) {
						var that = this;
						// #ifdef MP-WEIXIN
						uni.requestSubscribeMessage({
							tmplIds: this.tamplate_id,
							complete() {
								that.submitOrderInfo();
							}
						});
						// #endif

						// #ifndef MP-WEIXIN
						that.submitOrderInfo();
						// #endif
					} else {
						this.submitOrderInfo();
					}
				}, 1000);
			},

			// api提交订单
			submitOrderInfo() {
				uni.showLoading({
					title: "请稍等",
					mask: true
				});
				var submitData = this.submitData;
				var pay_type = this.submitData.payment;
				var submitDataInfo = JSON.parse(JSON.stringify(submitData));

				submitDataInfo.mch_list.forEach((el) => {
					el.integral = {
						forehead: Math.floor(el.integral.forehead),
						forehead_integral: Math.floor(el.integral.forehead_integral)
					};

					el.goods_list.forEach((e) => {
						e.integral = {
							forehead: Math.floor(e.integral.forehead),
							forehead_integral: Math.floor(e.integral.forehead_integral)
						};
					});
				});

                submitDataInfo.is_fugou = this.is_fugou;
				submitDataInfo.mch_list = JSON.stringify(submitDataInfo.mch_list);
				submitDataInfo.send_price = this.unionAll ? this.unionAll : 0;
				submitDataInfo.take_price = this.unionDis ? this.unionDis : 0;
				submitDataInfo.balance = this.balance ? this.balance : 0;
				submitDataInfo.activity_wechat_room_id =
					this.activity_wechat_room_id || "";
				if (this.is_integral) {
					let userInfo = uni.getStorageSync("userInfo");
					if (!userInfo) return;
					let userIntegral = Math.floor(userInfo.integral);
					if (this.all_price.all_integral > userIntegral) {
						if (!this.showCashDis) {
							uni.hideLoading();
							this.showCashDis = true;
							return;
						} else {
							this.showCashDis = false;
						}
					}
				}

				uni.showLoading({
					title: '正在提交...',
					mask:true
				});
				if (this.verify_card_id > 0)
					submitDataInfo.verify_card_id = this.verify_card_id;

				if (this.is_bug_level) {
					submitDataInfo.buy_level_id = this.is_bug_level;
				}
				let requestName = "submit";
				if (this.pt_number) {
					requestName = "ptSubmit";
				}
				if (this.activity_cut_price_order_id) {
					submitDataInfo.activity_cut_price_order_id =
						this.activity_cut_price_order_id;
				}

				if (this.is_seckill) {
					submitDataInfo.is_seckill = this.is_seckill;
				}

				if (this.is_worker) {
					let {
						id,
						default_date
					} = this.worker;
					submitDataInfo.is_worker = 1;
					submitDataInfo.worker_id = id;
					submitDataInfo.worker_time = default_date;
				}

				if (this.hasInvoice) {
					submitDataInfo.invoiceConf = JSON.stringify(this.$refs.invoice.form);
				}

				if (this.traceId) {
					submitDataInfo.is_wastore = 1;
					submitDataInfo.traceId = this.traceId;
				}
				console.log('submitDataInfo',submitDataInfo)

				if(!this.is_store_mch){
					submitDataInfo.newMd_id=1
				}

				this.$allrequest.order[requestName](submitDataInfo)
					.then((res) => {
						uni.hideLoading();
						if (res.code != 0) {
							return false;
						}

						if (res.data.douyin_url) {
							uni.setClipboardData({
								data: res.data.douyin_url,
								success() {
									uni.hideToast();
								}
							});
						}
						// 如果是货到付款订单跳转订单列表
						/*if (submitDataInfo.payment == 2) {
							return this.$utils.toUrl(`/order/order/order`);
						}
						// 如果是朋友代付跳转代付页面
						if (submitDataInfo.payment == 7) {
							return this.$utils.toUrl(
								`/order/pay-another/pay-another?orderId=${res.data.order_id}`
							);
						}*/
						let params = {
							payData: {
								order_id: res.data.order_id,
								order_id_list: res.data.order_id_list || "",
								pay_type: pay_type
							},
							backUrl: "/order/order/order",
							pay_type_list: this.pay_type_list,
							pay_price: this.submitData.pay_price,
							createDate: res.data.add_time
						};
						if (this.is_integral) {
							params.pay_price = res.data.order_price;
						}
						if (this.pt_number) params.backUrl = "/pt/order/index";

						if (this.is_worker)
							params.backUrl = "/marketing/serviceHome/order/list/index";
						this.$utils.toUrl(
							`/other/pay/pay?data=${JSON.stringify(params)}&is_pt=${
              this.pt_number
            }`,
							"redirectTo"
						);
					})
					.catch((err) => {
						uni.hideLoading();
						this.$utils.toast(err);
					});
			},

			// 点击配送方式swtich回调
			handleShop(e) {
				// 该数组，作为依据判断是否展示选择了门店
				this.send_type_arr.splice(e.index, 1, e.send_type);
			},

			// 显示支付弹框
			showPayPopup() {
				// this.$refs.pay_type_list.setShowPayPopup();
				this.showPayWayPopup = !this.showPayWayPopup;
			},
			// 选择支付方式回调
			payTypeSelect(e) {
				console.log('选择支付方式回调' , e);
				this.payType = e.type;
				this.submitData.payment = e.type;
				// 遍历数组
				for (var i = 0; i < this.pay_type_list.length; i++) {
					// 检查当前对象的 payType 属性是否等于 payment 属性
					if (this.pay_type_list[i].payment === this.payType) {
						// 如果相等，则打印该对象的 name 属性的值
						this.pmyName = this.pay_type_list[i].name;
					}
				}
				this.showPayWayPopup = false;
			},
			// 点击展示使用积分弹框
			handleIntegral() {
				this.$refs.integralUsePopup.showPopup();
			},
			// 点击展示使用余额弹框
			handleBalance() {
				this.$refs.balanceUsePopup.showPopup();
			},
			isUseIntegral(e) {
				this.useIntegral = e.status;
				this.setPayPrice();
				this.$refs.integralUsePopup.hidePopup();
			},
			isUseBalance(e) {
				this.useBalance = e.status;
				this.setPayPrice();
				this.$refs.balanceUsePopup.hidePopup();
			},
			getuserinfo(getDiy = true) {
				this.$allrequest.request.userindex({}, false).then((res) => {
					if (res.code == 0) {
						if (res.data.user_info && res.data.user_info.id > 0) {
							uni.setStorageSync("userInfo", res.data.user_info);
						}
					}
				});
			},

			bayVip(item) {
				let is_bug_level = "";
				if (!this.is_bug_level) {
					is_bug_level = item.id;
				}

				this.is_bug_level = is_bug_level;

				this.setPayPrice();
			},

			invoiceCallback(hasInvoice) {
				this.hasInvoice = hasInvoice;
				this.setPayPrice();
			}
		},

		computed: {
			isToday() {
				return (str) => {
					let d = new Date(str).setHours(0, 0, 0, 0),
						today = new Date().setHours(0, 0, 0, 0),
						weekDay = ["周天", "周一", "周二", "周三", "周四", "周五", "周六"];

					let obj = {
						"-86400000": "昨天",
						0: "今天",
						86400000: "明天"
					};

					if (obj[d - today]) {
						return obj[d - today];
					} else {
						let myDate = new Date(Date.parse(str));
						return weekDay[myDate.getDay()];
					}
				};
			},

			getRoomNum() {
				let num = 1;
				if (
					this.mch_list &&
					this.mch_list.length &&
					this.mch_list[0].goods_list.length
				) {
					num = this.mch_list[0].goods_list[0].num;
				}
				return num;
			},

			getDate() {
				if (!this.optionsData) return;
				let optionsData = this.optionsData[0];
				if (![1].includes(optionsData.product_type)) return null;

				let list = JSON.parse(JSON.stringify(optionsData.list)),
					startTime = list[0],
					endTime = list[list.length - 1];

				if (startTime) {
					startTime.month =
						parseInt(startTime.month) < 10 ?
						parseInt(startTime.month) :
						startTime.month;
					startTime.day =
						parseInt(startTime.day) < 10 ?
						parseInt(startTime.day) :
						startTime.day;
					startTime.value = `${startTime.month}月${startTime.day}日`;
				}

				if (endTime) {
					endTime.month =
						parseInt(endTime.month) < 10 ?
						parseInt(endTime.month) :
						endTime.month;
					endTime.day =
						parseInt(endTime.day) < 10 ? parseInt(endTime.day) : endTime.day;
					endTime.value = `${endTime.month}月${endTime.day}日`;
				}

				return [startTime, endTime, list.length - 1];
			},

			getTime() {
				if (!this.optionsData) return;
				let optionsData = this.optionsData[0];
				if (![2].includes(optionsData.product_type)) return null;

				let newList = JSON.parse(JSON.stringify(optionsData.list)),
					{
						time,
						date
					} = newList,
					hours = time.split("-"),
					startTime = `${date} ${hours[0]}`,
					endtTime = `${date} ${hours[1]}`,
					isToday = this.isToday;

				function fn(startTime = "", endtTime = "") {
					if (!startTime || !endtTime) {
						throw "参数不对";
					}
					let start = new Date(startTime.replace(/-/g, "/")).getTime(),
						end = new Date(endtTime.replace(/-/g, "/")).getTime();
					if (start < end) {
						[start, end] = [end, start];
					} else {
						if (endtTime.indexOf("00:00") !== -1) {
							end += 86400000;
						}
					}
					let cha = (start - end) / 1000,
						day = parseInt(cha / (60 * 60 * 24)),
						hour = Math.abs(parseInt((cha - 60 * 60 * 24 * day) / 60 / 60)),
						min = cha / 60;
					if (min === 30) {
						hour = "半";
					}
					let dateText = "",
						dateList = date.split("-"),
						d = parseInt(dateList[2]);

					dateText = `${parseInt(dateList[1])}月${d > 9 ? d : "0" + d}日`;

					return [dateText, isToday(date), time, hour + "小时"];
				}

				return fn(startTime, endtTime);
			},

			// 判断是否为积分订单
			is_integral() {
				if (this.mch_list && this.mch_list.length) {
					if (
						this.mch_list[0].name == `${this.stores.integral_name}商品` &&
						this.mch_list[0].goods_list[0].product_type == 4
					) {
						return true;
					} else {
						return false;
					}
				} else {
					return false;
				}
			}
		}
	};
</script>
<style lang="scss" scoped>
	.deliveryMoney {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 26rpx;
		padding: 30rpx 25rpx;
	}

	.sameCity {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 24rpx 0rpx;
		margin: 0rpx 25rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 26rpx;
		border-top: 1px solid #f8f8f8;
		border-bottom: 1px solid #f8f8f8;
	}

	.paymentMethod {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 702rpx;
		margin: 0 auto;
		background-color: #fff;
		border-radius: 20rpx;
		height: 96rpx;
		padding: 24rpx;
		margin-top: 24rpx;
		font-weight: 400;
		font-size: 26rpx;
	}

	.logisticsMethods {
		background-color: #fff !important;
		border-radius: 20rpx;
		position: relative;
		z-index: 2;
		overflow: hidden;
	}

	.logisticsMethods_text {
		height: 82rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;
		background-color: #fdeae7;

		// background: linear-gradient(to bottom, #FDEAE7, #FFF);
		/* 设置渐变颜色和方向 */
	}

	.text_style {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 30rpx;
		color: #191919;
		font-style: normal;
		text-transform: none;
		// width: 234rpx;
		height: 82rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-grow: 1;
	}

	/* index为1 */
	.text_style_active1 {
		font-weight: 600;
		background-color: #fff;
		// border-radius: 20rpx 20rpx 0rpx 0rpx;
	}

	.text_style_active2 {
		background-color: #fdeae7;
		// border-radius: 0rpx 0rpx 0rpx 20rpx;
	}

	.text_style_active3 {
		background-color: #fdeae7;
		// border-radius: 0rpx 20rpx 0rpx 0rpx;
	}

	/* index为2*/
	.text_style_active4 {
		background-color: #fdeae7;
		// border-radius: 20rpx 0rpx 20rpx 0rpx;
	}

	.text_style_active5 {
		font-weight: 600;
		background-color: #fff;
		// border-radius: 20rpx 20rpx 0rpx 20rpx;
	}

	.text_style_active6 {
		background-color: #fdeae7;
		// border-radius: 0rpx 20rpx 0rpx 20rpx;
	}

	/* index为3 */
	.text_style_active7 {
		background-color: #fdeae7;
		// border-radius: 20rpx 0rpx 0rpx 0rpx;
	}

	.text_style_active8 {
		background-color: #fdeae7;
		// border-radius: 0rpx 0rpx 20rpx 0rpx;
	}

	.text_style_active9 {
		font-weight: 600;
		background-color: #fff;
		// border-radius: 20rpx 20rpx 0rpx 0rpx;
	}

	.content {
		display: flex;
		align-items: center;

		height: 90rpx;
		margin: 0rpx 25rpx;
		border-bottom: 1px solid #f8f8f8;
	}

	.content_icon {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.addressNext {
		margin: 25rpx;
	}

	.content_text {
		font-family: PingFang SC, PingFang SC;
		font-weight: 600;
		font-size: 30rpx;
		color: #262626;
		font-style: normal;
		text-transform: none;
	}

	.content_txt {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #262626;
		font-style: normal;
		text-transform: none;
	}

	.inDetail {
		margin: 0rpx 25rpx;
		display: flex;
		justify-content: space-between;
		padding-bottom: 30rpx;
	}

	.inDetailContent {
		width: 408rpx;
		height: 68rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #8c8c8c;
		display: inline-block;
	}

	.inDetailColor {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #f0250e;
		font-style: normal;
		text-transform: none;
	}

	.inDetaiIcon {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 30rpx;
		margin-left: 40rpx;
	}

	.ml20 {
		margin-left: 20rpx;
	}

	.w575 {
		width: 575rpx;
	}

	// 更新---------------------
	/deep/.u-input__input {
		font-size: 26rpx !important;
		min-height: 36rpx !important;
		line-height: 36rpx !important;
	}

	/deep/.u-form-item {
		font-size: 26rpx !important;
		padding: 0 !important;
		line-height: 36rpx !important;
		margin: 30rpx 0 !important;
	}

	.unionAll {
		margin-top: 20rpx;
		padding: 0 24rpx;
		background: #ffffff;
		border-radius: 20rpx;
		display: flex;
		flex-direction: column;
		padding-bottom: 60rpx;

		.coupon-dis {
			display: flex;
			justify-content: space-between;
			margin-bottom: 30rpx;

			.dis-money {
				color: #f0250e;
				font-weight: bold;
			}
		}

		.coupon-back {
			display: flex;
			align-items: center;

			>span {
				display: block;
				width: 40rpx;
				height: 40rpx;
				text-align: center;
				line-height: 40rpx;
				background: #f0250e;
				border-radius: 8rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 600;
				color: #ffffff;
				margin-right: 10rpx;
			}

			p {
				font-size: 28rpx;
				font-weight: bold;

				span {
					font-size: 28rpx;
					color: #ff6113;
					font-weight: bold28;
				}
			}
		}
	}

	.submitorder {
		position: relative;
		min-height: 100vh;
		padding: 24rpx 24rpx 267rpx 24rpx;
		background-color: #f3f3f3;
	}

	.submitOrderCon {
		position: relative;
		z-index: 2;
	}

	.yuyue-info {
		background: #fff;
		padding: 0 30rpx;

		.yuyue-title {
			padding: 20rpx 0 0;
			line-height: 48rpx;
			font-size: 28rpx;
			font-weight: 600;
			color: #262626;
		}
	}

	.cashWarn {
		width: 600rpx;
		border-radius: 24rpx;
		overflow: hidden;
		background-color: #fff;

		.title {
			width: 100%;
			height: 90rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 32rpx;
			color: #262626;
			font-weight: 600;
		}

		.content {
			width: 100%;
			height: 128rpx;
			padding: 0 50rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			text-align: center;
			font-size: 28rpx;
			color: #262626;
		}

		.btns {
			width: 100%;
			height: 176rpx;
			padding: 0 50rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			text {
				width: 230rpx;
				height: 76rpx;
				border-radius: 99px;
				font-size: 32rpx;
				color: #262626;
				font-weight: 600;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			text:nth-child(1) {
				border: 1px solid #999;
				background-color: #fff;
			}

			text:nth-child(2) {
				background-color: #f0250e;
				color: #fff;
			}
		}
	}

	.submitorderHdBg {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 152rpx;
		z-index: 1;
		background: #f0250e;

		.casd {
			position: absolute;
			left: 0;
			top: 100%;
			width: 100%;
			height: 110rpx;
			background: linear-gradient(180deg, #f0250e 0%, #f2f2f2 100%);
		}
	}

	.select_ziti {
		display: flex;
		justify-content: space-between;
		align-items: center;
		color: red;
		padding: 0 30rpx;
	}

	.active {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 200rpx !important;
		z-index: 1;
		background: #f0250e;

		.casd {
			position: absolute;
			left: 0;
			top: 100%;
			width: 100%;
			height: 140rpx !important;
			background: linear-gradient(180deg, #f0250e 0%, #f2f2f2 100%);
		}
	}

	.m-box {
		background: #fff;
		margin-bottom: 24rpx;
		border-radius: 20rpx;
		padding: 0 24rpx;
	}

	.dateView {
		display: flex;
		align-items: center;
		padding: 30rpx 0;

		.time {
			display: flex;
			align-items: center;
			font-size: 32rpx;
			color: #262626;
			font-weight: bold;

			view {
				padding: 2rpx 0 0 6rpx;
				font-size: 28rpx;
				font-weight: normal;
			}
		}

		.and {
			padding: 0 24rpx;
			border-radius: 120rpx;
			color: #262626;
		}

		.totalNight {
			padding: 0 14rpx;
			margin: 0 10rpx;
			border: 1px solid #f2f2f2;
			color: #8c8c8c;
			font-size: 24rpx;
		}

		.andLast {
			padding-left: 0;
		}
	}

	.m-form {
		padding: 20rpx 0 0;

		.title {
			font-size: 28rpx;
			font-weight: bold;
			color: #262626;
		}

		.form {
			.item {
				padding: 20rpx 0;
				border-bottom: 1px solid #f8f8f8;

				&.first {
					padding-top: 0;
				}

				&:last-of-type {
					border-bottom: 0;
				}
			}
		}
	}

	::v-deep {

		.goodlist-item,
		.goodsfreight,
		.pay-select {
			border-radius: 20rpx;
		}

		.u-form-item--left__content--required {
			position: static !important;
		}
	}

	.item_input {
		font-weight: bold;
	}

	.notListPop {
		width: 80vw;
		padding: 0 30rpx;
		box-sizing: border-box;

		.title {
			margin-bottom: 24rpx;
			padding: 24rpx 0;
			font-size: 32rpx;
			color: #262626;
			font-weight: bold;
			text-align: center;
		}

		.item {
			display: flex;
			margin-bottom: 24rpx;
			border-radius: 20rpx;
		}

		.img {
			width: 176rpx;
			height: 176rpx;

			image {
				display: block;
				width: 100%;
				height: 100%;
				border-radius: 10rpx;
			}
		}

		.txt {
			margin-left: 26rpx;
			flex: 1;
			overflow: hidden;
		}

		.name {
			font-size: 28rpx;
			font-weight: bold;
			color: #262626;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}

		.sku {
			font-size: 22rpx;
			color: #8c8c8c;
		}

		.itemFd {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 8rpx 0;

			.price {
				color: #f0250e;
				font-size: 20rpx;

				text {
					font-size: 34rpx;
				}
			}

			.num {
				font-size: 24rpx;
				color: #262626;
			}
		}

		.error {
			font-size: 26rpx;
			color: #f0250e;
		}

		.btn {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 48rpx 20rpx;

			view {
				width: 230rpx;
				height: 76rpx;
				line-height: 76rpx;
				text-align: center;
				border: 2rpx solid #999999;
				border-radius: 32px;
				font-size: 32rpx;
				color: #262626;

				&.on {
					background: #f0250e;
					border-color: #f0250e;
					color: #fff;
				}
			}
		}
	}

	.levelBox {
		margin-top: 24rpx;
		padding: 6rpx;
		border-radius: 20rpx;
		background: #fff;

		.levelBoxCon {
			display: flex;
			align-items: center;
			padding: 18rpx;
			border-radius: 20rpx;
			border: 2rpx solid #f5e6e3;
		}
	}

	.levelLet {
		flex: 1;
		overflow: hidden;

		.des {
			padding: 0 8rpx;
			font-size: 28rpx;
			font-weight: bold;
			color: #262626;
		}

		.des2 {
			font-size: 24rpx;
			font-weight: bold;
			color: #c97d52;
		}

		.lv {
			display: inline-block;
		}

		.lvBox {
			display: flex;
			align-items: center;
			padding: 2rpx 4rpx;
			background: linear-gradient(91deg, #7e4238 0%, #311f1b 100%);
			border-radius: 4rpx;

			image {
				margin-right: 2px;
				width: 24rpx;
			}

			.name {
				font-size: 20rpx;
				color: #ffe4bc;
			}
		}
	}

	.levelRig {
		text-align: right;
		margin: 14rpx 10rpx 0;

		.price {
			padding: 0 8rpx;
			font-size: 28rpx;
			font-weight: bold;
			color: #262626;
		}

		.oldPrice {
			display: inline-block;
			position: relative;
			font-size: 24rpx;
			color: #8c8c8c;

			&:after {
				content: "";
				position: absolute;
				left: 0;
				top: 50%;
				right: 0;
				height: 1rpx;
				background: #8c8c8c;
			}
		}
	}

	.levelIcon {
		.iconfont {
			font-size: 48rpx;
			color: #707070;
		}

		.icon-success-fill {
			color: #f32524;
		}
	}

	.serviceHomeForm {
		margin-top: 24rpx;
		padding: 24rpx 24rpx 0;

		.title {
			display: flex;
			justify-content: space-between;
			padding-bottom: 16rpx;
			font-size: 28rpx;
			font-weight: bold;

			.iconfont {
				margin-right: 4rpx;
			}
		}

		.titleRig {
			font-weight: normal;
			padding: 4rpx 8rpx;
			font-size: 22rpx;
			background: #f2f2f2;
			border-radius: 4rpx;
		}

		.titleLet {
			display: flex;
			align-items: center;
		}

		.icon-arrow-right {
			font-size: 20rpx;
		}

		.serviceHomeItem {
			display: flex;
			padding: 14rpx 0;

			.let {
				margin-right: 64rpx;
				font-size: 26rpx;
				color: #262626;
			}

			.rig {
				display: flex;
				justify-content: space-between;
				align-items: center;
				flex: 1;
				overflow: hidden;
				font-weight: bold;
				font-size: 26rpx;
				color: #262626;
			}
		}

		.workerInfo {
			display: flex;
			align-items: center;

			image {
				margin-right: 10rpx;
				width: 36rpx;
				height: 36rpx;
				border-radius: 32px;
			}
		}

		.des {
			padding: 6rpx 0 30rpx;
			font-size: 26rpx;
			color: #8c8c8c;
		}

		.price {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 30rpx 0;
			border-top: 1px solid #f8f8f8;

			.rig {
				font-weight: bold;
			}
		}
	}
</style>
